package com.uhylab.uhuvinetest.fragment;

import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.uhylab.uhuvinetest.R;
import com.uhylab.uhuvinetest.activity.UHPhotoActivity;
import com.uhylab.uhuvinetest.base.UHBaseFragment;
import com.uhylab.uhuvinetest.utils.SceneAnimation;

/**
 * Created by xyb on 15/12/4 at UHylab
 *
 * @version 1.0
 */
public class UHHomeFragment extends UHBaseFragment implements View.OnClickListener {
    private GoDirect goDirect;
    private ImageView iv_homefragment;
    private TextView tv_homefragment;
    private int[] pFrameRess = new int[]{R.drawable._1, R.drawable._2, R.drawable._3, R.drawable._4, R.drawable._5, R.drawable._6, R.drawable._7, R.drawable._8, R.drawable._9, R.drawable._10,
            R.drawable._11, R.drawable._12, R.drawable._13,R.drawable._0
    };

    private int[] pDurations = new int[]{2000, 30, 30, 30, 30, 30, 30, 30, 30, 30,
            30, 30, 30, 30

    };

    private SceneAnimation sceneAnimation;
    private String fontPath;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
//        goPhoto = (GoPhoto) context;
//        goDirect = (GoDirect) context;
    }

    @Override
    public void initData() {
        iv_homefragment.setOnClickListener(this);
        tv_homefragment.setOnClickListener(this);
        Typeface tf = Typeface.createFromAsset(mActivity.getAssets(), fontPath);
        tv_homefragment.setTypeface(tf);
    }

    @Override
    protected void initDestrory() {
        if (sceneAnimation != null) {
            sceneAnimation.stop();
            sceneAnimation = null;
        }
    }

    @Override
    protected void initView() {
        //rippleView = (RippleView) view.findViewById(R.id.more);
        iv_homefragment = (ImageView) view.findViewById(R.id.iv_homefragment);
        tv_homefragment = (TextView) view.findViewById(R.id.tv_homefragment);
        sceneAnimation = new SceneAnimation(iv_homefragment, pFrameRess, pDurations);

        fontPath = "OpenSans-Regular.ttf";

        // Loading Font Face






    }

    @Override
    protected View inflaterView(LayoutInflater inflater, ViewGroup container) {
        view = inflater.inflate(R.layout.fragment_home, null);
        return view;
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.iv_homefragment:
               // goPhoto.gotoPhoto();

                Intent intent = new Intent(getContext(),UHPhotoActivity.class);
                startActivity(intent);

                break;
            case R.id.tv_homefragment:
                goDirect.gotoDirect();
                break;
        }


    }



    public interface GoDirect {
        void gotoDirect();
    }

    @Override
    public void onPause() {
        super.onPause();
        if (sceneAnimation != null) {
            sceneAnimation.stop();
            sceneAnimation = null;
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (sceneAnimation != null) {
            sceneAnimation.stop();
            sceneAnimation = null;
        }
    }
}
